package com.h5;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

public class H5BaseController {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	protected static final String BASE_PATH = "h5";
	
	public final static String SESSION_H5_USER="session_wap_user";
	
	@InitBinder  
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
        dateFormat.setLenient(false);  
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));  
    } 
	
	public String getSessionParameter(String name,HttpSession session) {
		Object obj = session.getAttribute(SESSION_H5_USER);
		if (obj != null) {
			HashMap<String, String> map = (HashMap<String, String>) obj;
			return map.get(name);
		}
		return "";
	}
	
	public String getSessionParameter(HttpSession session,String name) {
		Object obj = session.getAttribute(SESSION_H5_USER);
		if (obj != null) {
			HashMap<String, String> map = (HashMap<String, String>) obj;
			return map.get(name);
		}
		return "";
	}
	
	public void setSessionParameter(String name,String value,HttpSession session) {
		Object obj = session.getAttribute(SESSION_H5_USER);
		if (obj != null) {
			HashMap<String, String> map = (HashMap<String, String>) obj;
			map.put(name, value);
		}
	}

}
